home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / trans / deallocTempFilesPages.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.1 KB  |  162 lines

  1. /*
  2.  *   $RCSfile: deallocTempFilesPages.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:02 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "latch.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "bf_macro.h"
  57. #include "volume.h"
  58. #include "openlog.h"
  59. #include "trans.h"
  60. #include "page.h"
  61. #include "bitmap.h"
  62. #include "file.h"
  63. #include "consist.h"
  64. #include "deallocinfo.h"
  65. #include "bf_extfuncs.h"
  66. #include "fi_extfuncs.h"
  67. #include "io_extfuncs.h"
  68. #include "trans_intfuncs.h"
  69. #include "bf_globals.h"
  70. #include "io_globals.h"
  71.  
  72.  
  73. /*
  74.  *    This function deallocates the temporary files and pages allocated
  75.  *    by a transaction.
  76.  */
  77.  
  78.  void
  79. deallocTempFilesPages (
  80.  
  81.     TRANSREC        *transRec
  82. )
  83. {
  84.  
  85.     PAGEDEALLOCINFO *currPage;
  86.     FILEDEALLOCINFO *currFile;
  87.     PAGE2SIZE        page2size, prevPage2size;
  88. #define                PID_LIST_LEN    10
  89.     PID                pidList[PID_LIST_LEN];
  90.     VOLREC            *volRec;
  91.     int                i;
  92.  
  93.  
  94.     TRACE(TR_TRANS, TR_LEVEL_1);
  95.  
  96.     /*
  97.      *    Destroy each temporary file
  98.      */
  99.     while ((currFile = (FILEDEALLOCINFO*) listDeq(&(transRec->tempFileList))) != NULL) {
  100.  
  101.         volRec = io_FindVolRec(currFile->fid.pid.volid);
  102.         if (volRec == NULL) {
  103.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  104.         }
  105.  
  106.         if (io_MarkPage(volRec, &(currFile->fid.pid), PAGE_FILEHDR, FALSE) != esmNOERROR)   {
  107.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  108.         }
  109.  
  110.         if (fi_DestroyFile(UserBufGroup, &(currFile->fid.pid), NULL, TRUE, FALSE) != esmNOERROR)  {
  111.             SM_ERROR(TYPE_CRASH, esmINTERNAL);
  112.         }
  113.         poolEnq(&FileDeallocInfoPool, &(currFile->list));
  114.     }
  115.  
  116.  
  117.     /*
  118.      *    Deallocate pages in chunks of PID_LIST_LEN
  119.      */
  120.     i = 0;
  121.     while ((currPage = (PAGEDEALLOCINFO*) listDeq(&(transRec->tempPageList))) != NULL) {
  122.  
  123.         CHECK_PAGEDEALLOCINFO_MAGIC(currPage);
  124.         page2size = currPage->page2size;
  125.  
  126.         /* 
  127.          *    if the page list is full, or we came across is different
  128.          *    type of page and we are not at the first page of the
  129.          *    pidList, deallocate what we have to far.
  130.          */
  131.         if (i == PID_LIST_LEN || (prevPage2size != page2size && i != 0)) {
  132.             if (io_DeallocPages(prevPage2size, i, pidList, NULL, FALSE, TRUE) != esmNOERROR) {
  133.                 SM_ERROR(TYPE_CRASH, esmINTERNAL);
  134.             }
  135.  
  136.             i = 0;
  137.         }
  138.  
  139.         if (i == 0) {
  140.             prevPage2size = page2size;    
  141.         }
  142.         pidList[i] = currPage->pid;
  143.  
  144.         /*
  145.          *    Remove the page from the buffer and
  146.          *    Return the page info to the Pool
  147.          */
  148.         bf_InvalidatePage(&(currPage->pid));
  149.         poolEnq(&PageDeallocInfoPool, &(currPage->list));
  150.  
  151.         i++;
  152.     }
  153.  
  154.     /* finish deallocating */
  155.     if (i > 0) { 
  156.         if (io_DeallocPages(prevPage2size, i, pidList, NULL, FALSE, TRUE) != esmNOERROR) {
  157.             SM_ERROR(TYPE_CRASH, esmINTERNAL);
  158.         }
  159.     }
  160. }
  161.  
  162.